/*
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
*/

/**
 * Definition for binary tree
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    void ToBSTHelper(TreeNode **node, int low, int high, vector<int> &num) {
        if (low > high) return;
        int mid = (low+high)/2;
        TreeNode *n = new TreeNode(num[mid]);
        *node = n;
        ToBSTHelper(&n->left, low, mid-1, num);
        ToBSTHelper(&n->right, mid+1, high, num);
    }
    TreeNode *sortedArrayToBST(vector<int> &num) {
        TreeNode *root = NULL;
        ToBSTHelper(&root, 0, (int)num.size()-1, num);
        return root;
    }
};
